import time
import numpy as np
from RA_Cal import ReflectArray_cal_FFT, Para_RA, MASK_rp, Costfunction, csvtest
import random

if __name__ == '__main__':
    import GAMp

    Costfunction_400 = Costfunction.Costfunction_tt(400)
    ga_test = GAMp.GAMp(fitness_func=Costfunction_400.CostFunction, n=Costfunction_400.n_code,
                    num_populations=2, population_size=500, generations=1000)
    optimized_code, optimized_result = ga_test.run()

    # Code_bestsofar = csvtest.Read_csv_inrows(r"best\best_1.csv", [0])[:, 0]
    # popu_rand = [random.randint(0, 1) for _ in range(len(Code_bestsofar))]
    # # Code_bestsofar = csvtest.Read_csv_inrows(r"GA_test_22.csv", range(cf.n_code))[-1]
    # st = time.time()
    # print(cf.CostFunction(0, Code_bestsofar))
    # print("cf time: ", time.time()-st)
    #
    # print("")
    # print(cf.CostFunction_View(0, Code_bestsofar))
    # print("")

    # Code_bestsofar = csvtest.Read_csv_inrows(r"best\best_2.csv", [0])[:, 0]
    # # Code_bestsofar = csvtest.Read_csv_inrows(r"GA_test_22.csv", range(cf.n_code))[-1]
    # print(cf2.n_code)
    # print(cf2.CostFunction_View(Code_bestsofar))
    # print("")
    #
    # popu_rand = [random.randint(0, 1) for _ in range(len(Code_bestsofar))]
    # print(Costfunction.CostFunction_View(popu_rand))